package com.lgq.service;

import com.lgq.bean.Student;
import com.lgq.bean.StudentExample;
import com.lgq.dao.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: stu_info_manager
 * @description:
 * @author: Lin
 * @create: 2019-01-05 00:07
 **/
@Service
public class StudentService {

    /**
     * 自动装配studentMapper
     */
    @Autowired
    StudentMapper studentMapper;

    /**
     * 获取全部学生信息
     * @return
     */
    public List<Student> getAll(){
        return studentMapper.selectByExampleWithInstitute(null);
        //return studentMapper.selectByExample(null);
    }


    /**
     * 有选择保存插入指定学生
     * @param student
     */
    public void saveStudent(Student student) {
        studentMapper.insertSelective(student);
    }

    /**
     * 获取指定ID的学生信息
     * @param id
     * @return
     */
    public Student getStu(Integer id) {
        Student student=studentMapper.selectByPrimaryKey(id);
        return student;
    }


    /**
     * 有选择更新学生通过ID值
     * @param student
     */
    public void updateStudent(Student student) {
        studentMapper.updateByPrimaryKeySelective(student);
    }


    /**
     * 通过学生的ID删除指定学生
     * @param id
     */
    public void deleteStudentById(Integer id) {
        studentMapper.deleteByPrimaryKey(id);
    }

    /**
     * 通过List集合批量删除学习信息
     * @param deleteList
     */
    public void deleteBatch(List<Integer> deleteList) {
        StudentExample studentExample=new StudentExample();
        StudentExample.Criteria criteria = studentExample.createCriteria();
        criteria.andStuIdIn(deleteList);
        studentMapper.deleteByExample(studentExample);
    }
}
